package connect.service;

import io.netty.channel.ChannelHandlerContext;
import io.netty.util.internal.ConcurrentSet;

public class Client {

	private Object msg;//来自客户端的消息
	private ChannelHandlerContext context;//发送器
	private ConcurrentSet<Connection> list;//在线连接列表
	
	/**
	 * 构造
	 * @param msg
	 * @param context
	 * @param list
	 */
	public Client(final ConcurrentSet<Connection> list) {
		this.list=list;
	}
	
	/**
	 * 返回消息
	 * @return
	 */
	public Object getMessage() {
		return msg;
	}
	
	/**
	 * 发送消息
	 * @param msg
	 */
	public void sendContent(final Object msg) {
		context.writeAndFlush(msg);
	}
	
	/**
	 * 设置标记
	 * 此标记用于达到点对点,点对多点
	 * 简单点说:像游戏 公聊与私聊
	 * @param key
	 */
	public void setKey(final String key) {
		for (Connection c : list) {
			if (c.getContext()==context) {
				c.setKey(key);
			}
		}
	}
	
	public void setMessage(final Object msg) {
		this.msg=msg;
	}
	
	public void setContext(final ChannelHandlerContext context) {
		this.context=context;
	}
	
	public ChannelHandlerContext getContext() {
		return context;
	}
	
	
}
